package com.yf.controller.admin.course;

import java.util.List;
import java.util.Map;

import com.yf.entity.course.CourseEntity;
import com.yf.entity.course.LessonEntity;
import com.yf.service.course.LessonService;
import com.yf.vo.LessonBackVo;
import com.yf.vo.OptCourseBackVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 章节Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Oct 31 09:51:27 CST 2018
 */
@RestController
@RequestMapping("/lesson")
public class LessonController {
    @Autowired
    private LessonService lessonService;

    /**
     * 列表章节
     */
    @RequestMapping("/list")
    @RequiresPermissions("lesson:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<LessonEntity> lessonList = lessonService.queryList(params);
        return R.ok(new PageInfo(lessonList));
    }

    /**
     * 查看章节
     */
    @SysLog("查看章节")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lesson:info")
    public R info(@PathVariable("id") Long id) {
        LessonEntity lesson = lessonService.get(id);

        return R.ok(lesson);
    }

    /**
     * 保存章节
     */
    @SysLog("保存章节")
    @RequestMapping("/save")
    @RequiresPermissions("lesson:save")
    public R save(LessonEntity lesson) {
        lessonService.save(lesson);

        return R.ok(lesson);
    }

    /**
     * 修改章节
     */
    @SysLog("修改章节")
    @RequestMapping("/update")
    @RequiresPermissions("lesson:update")
    public R update(LessonEntity lesson) {
        lessonService.update(lesson);

        return R.ok(lesson);
    }

    /**
     * 删除章节
     */
    @SysLog("删除章节")
    @RequestMapping("/delete")
    @RequiresPermissions("lesson:delete")
    public R delete(@RequestBody Long[]ids) {
        lessonService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有章节
     */
    @SysLog("所有章节")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<LessonEntity> lessonList = lessonService.queryList(params);

        return R.ok(lessonList);
    }

    /***********自定义开始***********/

    /**
     * back 章节信息
     * @return
     */
    @RequestMapping("/lessonList")
    public R getCampaignVoList(@RequestParam Map<String, Object> params){
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<LessonBackVo> list = lessonService.lessonList(params);
        return R.ok(new PageInfo(list));
    }

    /**
     * 章节选择课程
     * @return
     */
    @RequestMapping("/getCourseList")
    public R getCourseList(){
        List<OptCourseBackVo> list = lessonService.courseList();
        return R.ok("OK",list);
    }

}
